import Vue from 'vue'
import VueRouter from 'vue-router'
import RightMenu from '@/layout/right-menu.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'index',
    component: () => import('@/views/index.vue'),
    meta: { title: '首页-参考文档' }
  },
  {
    path: "/web",
    component: RightMenu,
    meta: { title: '参考文档' },
    children: [
      {
        path: 'html/:path+',
        name: 'html',
        component: () => import('@/views/lesson-html/index.vue'),
        meta: { title: 'HTML 基础' }
      },
      {
        path: 'css/:path+',
        name: 'css',
        component: () => import('@/views/lesson-css/index.vue'),
        meta: { title: 'CSS 基础' }
      },
      {
        path: 'javascript/:path+',
        name: 'JavaScript',
        component: () => import('@/views/lesson-javascript/index.vue'),
        meta: { title: 'JavaScript基础' }
      },
      {
        path: 'es6/:path+',
        name: 'es6',
        component: () => import('@/views/lesson-es6/index.vue'),
        meta: { title: 'ES6 基础' }
      },
      {
        path: 'webapi/:path+',
        name: 'webapi',
        component: () => import('@/views/lesson-webapi/index.vue'),
        meta: { title: 'WebApi 基础' }
      },
      {
        path: 'bash/:path+',
        name: 'bash',
        component: () => import('@/views/lesson-bash/index.vue'),
        meta: { title: 'bash 基础' }
      },
      {
        path: 'ssh/:path+',
        name: 'ssh',
        component: () => import('@/views/lesson-ssh/index.vue'),
        meta: { title: 'ssh 教程' }
      },
      {
        path: 'menu/:path+',
        name: 'ssh',
        component: () => import('@/views/lesson-menu/index.vue'),
        meta: { title: 'ssh 教程' }
      }
    ]
  },
  {
    path: '/about-me',
    name: 'AboutMe',
    component: () => import('@/views/aboutMe/index.vue'),
    meta: { title: '关于我-前端参考文档' }
  },
  {
    path: '/game',
    name: 'Game',
    component: () => import('@/views/aboutMe/game-list.vue'),
    meta: { title: '概率小游戏' },
    children: [
      {
        path: 'seven',
        name: 'Seven',
        component: () => import('@/views/aboutMe/seven-star-lotto.vue'),
        meta: { title: '七星彩' }
      },
      {
        path: 'pair',
        name: 'Pair',
        component: () => import('@/views/aboutMe/pair-color-lotto.vue'),
        meta: { title: '双色球' }
      },
      {
        path: 'all',
        name: 'All',
        component: () => import('@/views/aboutMe/all.vue'),
        meta: { title: '体彩' }
      }
    ]
  },
  {
    path: '/download',
    name: 'Download',
    component: () => import('@/views/download/index'),
    meta: { title: '文档下载-前端参考文档' }
  },
  {
    path: '/demoList',
    name: 'DemoList',
    component: () => import('@/views/demoList/index.vue'),
    meta: { title: '演示-前端参考文档' }
  },
  {
    path: '/demo',
    name: 'Demo',
    component: () => import('@/views/demo/index.vue'),
    meta: { title: '演示-前端参考文档' }
  },
  {
    path: '/lessons',
    name: 'Lessons',
    component: () => import('@/views/lessons/index.vue'),
    meta: { title: '课件-参考文档' }
  },
  {
    path: '/htmlView',
    name: 'Lessons',
    component: () => import('@/views/lessons/htmlView.vue'),
    meta: { title: '课件-预览html' }
  },
  {
    path: '/log',
    name: 'log',
    component: () => import('@/views/aboutMe/log.vue'),
    meta: { title: '课件-参考文档' }
  },
  {
    path: '/test/mousedown',
    name: 'mousedown',
    component: () => import('@/views/test/mousedown.vue'),
    meta: { title: '示例' }
  },
  {
    path: '/test/mousedown1',
    name: 'mousedown1',
    component: () => import('@/views/test/mousedown1.vue'),
    meta: { title: '示例' }
  },
  {
    path: '/test/parent-slot',
    name: 'ParentSlot',
    component: () => import('@/views/test/parent-slot.vue'),
    meta: { title: '示例' }
  },
  {
    path: '/game/add',
    name: 'GameAdd',
    component: () => import('@/views/aboutMe/game/add.vue'),
    meta: { title: '添加游戏' }
  },
  {
    path: '*',
    name: '404',
    component: () => import('@/views/404.vue'),
    meta: { title: '页面不存在' }
  }
]

const router = new VueRouter({
  routes,
  //mode: 'history'  // /*hash*/ /*不显示路由中的#*/   history添加此行即可
})

// 防止路由重复点击报错
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (to) {
  return VueRouterPush.call(this, to).catch(err => err)
}
// 全局前置守卫，设置页面标题
router.beforeEach((to, from, next) => {
  // NProgress.start()
  document.title = to.matched[0].meta.title
  next();
});
// history 
export default router